﻿/* 
 * Copyright (c) 2010 Letwory Interactive
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * -- Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * -- Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * Original contributor: Nathan Letwory
 */

using System;

namespace VerseSharp
{
    public delegate void BitmapLayerSubscribeCallback(BitmapLayerSubscribeCommand command);
    public delegate void BitmapLayerUnsubscribeCallback(BitmapLayerSubscribeCommand command);

    /// <summary>
    /// Command to subscribe or unsubscribe to a bitmap layer.
    /// </summary>
    public class BitmapLayerSubscribeCommand: IVerseCommand
    {
        /// <summary>
        /// Protocol ID of the command.
        /// </summary>
        public CommandID ID { get { return CommandID.BitmapLayerSubscribe; } }
        /// <summary>
        /// ID of the node being accessed.
        /// </summary>
        public uint NodeID;
        /// <summary>
        /// ID of the layer to subscribe to.
        /// </summary>
        public ushort LayerID;
        /// <summary>
        /// Mipmap level to get. 0 is the base level, meaning you get the full resolution. 1 means 1/8th of the resolution.
        /// Setting this to byte.MaxValue means to unsubscribe.
        /// Editing is allowed only on the base level.
        /// </summary>
        public byte Level;

        public void Deserialize(byte[] source, ref int pos)
        {
            NodeID = Utils.GetUInt32(source, ref pos);
            LayerID = Utils.GetUInt16(source, ref pos);
            Level = Utils.GetUInt8(source, ref pos);
        }

        public void Serialize(byte[] destination, ref int pos)
        {
            Utils.PutUInt32(destination, ref pos, NodeID);
            Utils.PutUInt16(destination, ref pos, LayerID);
            Utils.PutUInt8(destination, ref pos, Level);
        }
    }
}
